package model
{
  import flash.events.EventDispatcher;
  import flash.events.IEventDispatcher;
  
  import model.proxys.CardProxy;
  
  import mx.collections.ArrayCollection;

  public class DataManager extends EventDispatcher
  {
    [Bindable]
    public var aCardsInAlbum:ArrayCollection;
    
    [Bindable]
    public var aCardsInStack:ArrayCollection;
    
    public function DataManager(target:IEventDispatcher=null)
    {
      super(target);
      
      aCardsInAlbum = new ArrayCollection();
      aCardsInStack = new ArrayCollection();
    }
    
    public function setCardDaraFromXML(xml:XML):void
    {
      trace("DataManager » setCardDaraFromXML");
      
      aCardsInAlbum.removeAll();
      
      for each (var item:XML in xml.descendants("card"))
        aCardsInAlbum.addItem(new CardProxy(item.@name, item.@image, item.@thumb));
    }
    
    public function addCardToStack(proxy:CardProxy):void
    {
      if (proxy == null) return;
      
      if (!aCardsInStack.contains(proxy))
        aCardsInStack.addItem(proxy);
      
      proxy.cardStackQuantity += 1;
    }
  }
}